import{request} from '../../network/index'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		userinfo:'',
		music:[],
		show: false,
	},
	showPopup() {
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },
	async toLike(){
		let ids = this.data.music.join()
		const musicList = await request('/song/detail',{ids})
		console.log(musicList);
		wx.navigateTo({
			url: '/pages/likeMuic/likeMusic',
			success(res){
				res.eventChannel.emit('getMusic',musicList.data.songs)
			}
		})
	},
	//最近播放
	toNewPlay(){
		
	},
	toLogin(){
		let token = wx.getStorageSync('cookies')
		if(token){
			wx.showModal({
				title: '退出登陆',
					success:async (res) => {
					if(res.confirm){
						let logout = await request('/logout')
						if(logout.data.code === 200){
							this.setData({
								userinfo:''
							})
							wx.setStorageSync('profile','')
							wx.setStorageSync('cookies','')
						}
					}
				}
			})
		}else{
			wx.navigateTo({
				url: '/pages/login/login',
			})
		}
	
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: async function () {
		let userinfo = wx.getStorageSync('profile')
		let linkList = await request('/likelist',{uid:userinfo.userId})
		this.setData({
			userinfo:userinfo,
			music:linkList.data.ids
		})
		//播放历史记录
		// let playHistory = await request('/user/record',{uid:userId.userId,type:0})
	},	

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})